package com.carlinfo.hospital.service.impl;

import com.carlinfo.hospital.dao.impl.PersonDaoimpl;
import com.carlinfo.hospital.pojo.Doctor_person;
import com.carlinfo.hospital.pojo.Person;
import com.carlinfo.hospital.service.PersonService;
import com.carlinfo.hospital.util.PageInfoUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class PersonServiceImpl implements PersonService
{
    @Autowired
    private PersonDaoimpl personDaoimpl;

    @Autowired
    private Doctor_personServiceImpl doctor_personService;

    @Override
    public int saveOnePersonService(Person person)
    {
        return personDaoimpl.saveOneDao(person);
    }

    @Override
    public List<Person> selectListPersonService(PageInfoUtil pageInfoUtil, Map<String, Object> condMap)
    {
        List<Person> personList = new ArrayList<Person>();
        if (condMap.get("doctorId")!= null)
        {
            List<Doctor_person> doctor_people = this.doctor_personService.selectListDao(pageInfoUtil, condMap);
            for (int i = 0; i < doctor_people.size(); i++)
            {
                Map<String, Object> maap = new HashMap<String, Object>();
                maap.put("id", doctor_people.get(i).getPersonId());
                Person person = this.personDaoimpl.selectOneDao(maap);
                personList.add(person);
            }
            return personList;
        }
        return personDaoimpl.selectListDao(pageInfoUtil, condMap);
    }

    @Override
    public Person selectOnePersonService(Map<String, Object> condMap)
    {
        return personDaoimpl.selectOneDao(condMap);
    }

    @Override
    public int updateOnePersonService(Person person)
    {
        return personDaoimpl.updateOneDao(person);
    }

    @Override
    public int deleteOnePersonService(Map<String, Object> condMap)
    {
        return personDaoimpl.deleteOneDao(condMap);
    }
}
